import request from '@/config/axios'

// 家族成员 VO
export interface MembersVO {
  id: number // 主键ID
  name: string // 成员姓名
  gender: number // 性别（男/女/其他）
  birthDate: string // 出生日期
  deathDate: string // 逝世日期（可选）
  contactInfo: string // 联系方式
  photoUrl: string // 成员照片URL
  biography: string // 成员生平简介
  generation: number // 成员在家族中的代数
  createTime: Date // 创建时间
}

export interface MemberRelationVO {
  name: string
  gender: number | undefined
  relationType: number | undefined
  birthDate: string
  deathDate: string
  contactInfo: string
  photoUrl: string
  biography: string
  generation: number
  relationMemberId: number
}

export interface MemberVO {
  id: number
  name: string
  gender: number
  birthDate: string
  deathDate?: string
  generation: number
  children?: MemberVO[]
  mate?: MemberVO[]
}

export interface FamilyRelationshipVO {
  id: number
  memberId: number
  relativeId: number
  relationType: string
  relationName: string
}

// 家族成员 API
export const MembersApi = {
  // 查询家族成员分页
  getMembersPage: async (params: any) => {
    return await request.get({ url: `/family/members/page`, params })
  },

  // 查询家族成员详情
  getMembers: async (id: number) => {
    return await request.get({ url: `/family/members/get?id=` + id })
  },

  // 新增家族成员
  createMembers: async (data: MembersVO) => {
    return await request.post({ url: `/family/members/create`, data })
  },

  // 修改家族成员
  updateMembers: async (data: MembersVO) => {
    return await request.put({ url: `/family/members/update`, data })
  },

  // 删除家族成员
  deleteMembers: async (id: number) => {
    return await request.delete({ url: `/family/members/delete?id=` + id })
  },

  // 导出家族成员 Excel
  exportMembers: async (params) => {
    return await request.download({ url: `/family/members/export-excel`, params })
  },

  // 创建家族成员关系
  createMemberRelation: async (data: MemberRelationVO) => {
    return await request.post({ url: '/family/members/relation/create', data })
  },

  addRelationMember: async (data: MemberRelationVO) => {
    return await request.post({ url: '/family/members/add-relation-person', data })
  },

  // 获取家族树
  getFamilyTree: async () => {
    return await request.getOriginal({ url: '/family/members/tree' })
  },

  // 获取家族成员详情
  getMember: async (id: number) => {
    return await request.get({ url: `/family/members/get?id=${id}` })
  },

  // 创建家族成员
  createMember: async (data: Omit<MemberVO, 'id'>) => {
    return await request.post({ url: '/family/members/create', data })
  },

  // 更新家族成员
  updateMember: async (data: MemberVO) => {
    return await request.put({ url: '/family/members/update', data })
  },

  // 删除家族成员
  deleteMember: async (id: number) => {
    return await request.delete({ url: `/family/members/delete?id=${id}` })
  },

  // 获取成员列表
  getMemberPage: async (params: any) => {
    return await request.get({ url: '/family/members/page', params })
  }
}

// 为了方便导入，直接导出方法
export const getFamilyTree = MembersApi.getFamilyTree
export const getMember = MembersApi.getMember
export const createMember = MembersApi.createMember
export const updateMember = MembersApi.updateMember
export const deleteMember = MembersApi.deleteMember
export const getMemberPage = MembersApi.getMemberPage
